/**
 * 分类书籍 ---- 热门榜单
 * @author Qasim <15750783791@163.com>
 * @version 2016/10/31
 */
document.addEventListener('plusready' ,ready , false);

var self = ''
function ready(){
	self = plus.webview.currentWebview();
	loadMore();
}


/**
 * 分页加载数据
 * @param {Int} page [开始页]
 */
function loadMore(page  , isEnable){ 
	if(!page)page = 1;
	$.ajax({
		type:"post",  
		url:apiRoot + "/Home/Article/loadMore/", 
		data:{
			tid : 34 ,
			page :  page 
		},
		beforeSend:function(){
			plus.nativeUI.showWaiting('加载中...');
		},
		complete:function(){
			plus.nativeUI.closeWaiting();
		},
		dataType:'json', 
 		success : function(data){ 
			if(data != ''){
				$.each(data, function(k ,v) {
					var html  = '<div class="list-p" data-id="'+v.id+'"><ul class="mui-table-view">';
						html += '<li class="mui-table-view-cell mui-media"><a href="javascript:void(0);" class="details" data-id="'+v.id+'">';
						html += '<img class="mui-media-object mui-pull-left" src="'+getImgUrl(v.litpic , "../public/img/book.jpg")+'">';
						html += '<div class="mui-media-body"><span class="mui-h5 back">'+v.book_name+'</span>';
						if(page == 1){
							switch (k){
								case 0:
									html += '<span class="biaoji"><i class="mui-icon iconfont mui-red">&#xe611;</i></span>';
									break;
								case 1:
									html += '<span class="biaoji"><i class="mui-icon iconfont mui-lvs">&#xe612;</i></span>';
									break;
								case 2:
									html += '<span class="biaoji"><i class="mui-icon iconfont mui-zi">&#xe613;</i></span>';
									break;
								default:
									break;
							}
						}
					html += '<p class="mui-h6 detail">'+v.description+'</p>';
					html += '<p class="autor"><span class="mui-h6 back">'+v.author+'</span>';
					html += '</p></div></a></li></ul></div>';
					$('.lists').append(html);  
					$('.list-p').unbind();
				    $('.list-p').on('click' , function(){ 
				    	var parameter = {aid : $(this).attr('data-id')};
				    	goUrl('book-detail.html' , 'book_detail' , parameter);
				    });
				}); 
				if(isEnable)isEnable.endPullUpToRefresh(false); 
			}else{ 
				toast('没有更多的数据了');
				if(isEnable)isEnable.endPullUpToRefresh(true); 
			}
		},
		error : function(e){
			errorPrompt(e);
		}
	});
}
